<?php
/// http://112.126.87.223/master/mcGM/tmp_process/itry_idfa_recv.php?idfa=123&device_id=d41d8cd98f00b204e9800998ecf8427eee482dea

define("APP_ROOT",dirname(__FILE__) . "/");

include APP_ROOT . "cur_db_cfg.php";

# 解析URL数据
#$row_data = $_GET;
$appid = '1065398803';
$row['device_id'] = $_REQUEST['device_id'];
$row['idfa'] = $_REQUEST['idfa'];

$query = "SELECT * FROM device_lan WHERE device_id = '" . $_REQUEST['device_id'] . "'";

$conn=mysql_connect($dbhost_idfa,$dbaccount_idfa,$dbpwd_idfa);
mysql_select_db("shouhuzhemen_account");
$result_db = mysql_query($query);

#var_dump($result_db);
if(true == $result_db)
{
    db_option($row, $appid);
}
else
{
    $tmp_array = array();
    $tmp_array['success'] = false;
    $tmp_array['message'] = $row['idfa'];
    $json_str = json_encode($tmp_array);
    echo($json_str);
}

function db_option($rowdata, $appid)
{
    $strdata = "insert into device_lan(device_id, appid, idfa) values('";
    $strdata = $strdata . $rowdata['device_id'] . "', '";
    $strdata = $strdata . $appid . "', '";
    $strdata = $strdata . $rowdata['idfa'] . "') on duplicate key update ";
    $strdata = $strdata . "appid='$appid',";
    $strdata = $strdata . "idfa='$rowdata[idfa]'";
    
    #echo($strdata . "<br>");
    $result_db=mysql_query($strdata);
    #var_dump($result_db);
    if(true == $result_db)
    {
        $tmp_array = array();
        $tmp_array['success'] = true;
        $tmp_array['message'] = "ok";
        $json_str = json_encode($tmp_array);
        echo($json_str);
    }
    else
    {
        $tmp_array = array();
        $tmp_array['success'] = false;
        $tmp_array['message'] = "false";
        $json_str = json_encode($tmp_array);
        echo($json_str);
    }
}
?>
